/*
 * @Description: 
 * @Author: zyj
 * @Date: 2022-05-27 17:13:53
 * @LastEditors: zyj
 * @LastEditTime: 2022-05-27 17:14:11
 */
/* 对象的getter和setter */
let obj1 = {
  other: '123',
  get name() {
    return this.other;
  },
  set name(val) {
    this.other = val;
  }
}
console.log(obj1.name);
obj1.name = 456;
console.log(obj1.name);


let obj2 = {
  name: '张三',
}


let globalObj = {
  name: 'global',
}


Object.defineProperty(obj2, "fn", {
  configurable: true,
  enumerber: true,
  get() {
    return function () {
      console.log(this.name);
    }
  },
  set(val) {


  }
});
Object.defineProperty(obj2, "age", {
  configurable: true,
  enumerber: true,
  get() {
    console.log("访问了age属性");
    return 18
  },
  set(val) {
    console.log("给age属性设值");
  }
})


console.log(obj2);